﻿@using GameSchoolApplication.Models
@model IEnumerable<GameSchoolApplication.Models.StudentPoints>

@{
    ViewBag.Title = "Mínir leikir";
    Layout = "~/Views/Shared/_StudentLayout.cshtml";
}

@helper LevelPoints(Level level)
{
    var participation = level.GetStudentParticipation(ViewBag.Student);
    if(participation != null)
    {
        if(participation.Points != null)
        {
            @participation.Points
        }
        else
        {
            <span>Engin stig</span>
        }
    }
    else
    {
        <span>Borð ekki hafið.</span>
    }
}

@helper NearestGamePoints(StudentPoints entry)
{
    var nearest = entry.NearestPoints;
    if (nearest.Item1 != null)
    {
        <p>Næsti fyrir ofan: @nearest.Item1.Points</p>
    }
    else
    {
        <p>Enginn fyrir ofan.</p>
    }
    if (nearest.Item2 != null)
    {
        <p>Næsti fyrir neðan: @nearest.Item2.Points</p>
    }
    else
    {
        <p>Enginn fyrir neðan.</p>
    }
}

@helper NearestLevelPoints(StudentLevelPoints entry)
{
    if(entry != null)
    {
        var nearest = entry.NearestPoints;
        if (nearest.Item1 != null)
        {
            <p>Næsti fyrir ofan: @nearest.Item1.Points</p>
        }
        else
        {
            <p>Enginn fyrir ofan.</p>
        }
        if (nearest.Item2 != null)
        {
            <p>Næsti fyrir neðan: @nearest.Item2.Points</p>
        }
        else
        {
            <p>Enginn fyrir neðan.</p>
        }
    }
}

@section More {
<section id="More">
    <ul>
        <li><a href="#" id="showdes">Upplýsingar um leik</a></li>
        <li><a href="#" id="showlvl">Borð</a></li>
        <li><a href="#" id="showpoint">Stig leiks</a></li>
        <li>@Html.ActionLink("Svindlarahornið", "#", "#")</li>
    </ul>
</section>
        }
<div class="tabbed" id="Student">
    <ul>
        @foreach (var gameEntry in Model)
        {
            <li class="tabs"><a href="#game-@gameEntry.GameId">@gameEntry.Game.Title</a></li>
        }
    </ul>
    
    @foreach (var gameEntry in Model)
    {
        <div id="game-@gameEntry.GameId">
            <div class="gamedescription">
                <p>@gameEntry.Game.Description</p>
            </div>
            <div class="gamelevellist">
                <ol>
                   @foreach (var level in gameEntry.Game.Levels)
                   {
                        <li class="level">
                            <p>Borð: @level.Title<br />
                            Stig: @LevelPoints(level)</p>
                            @NearestLevelPoints(level.GetStudentParticipation(ViewBag.Student))
                        </li>
                   }
                </ol>
                @Html.ActionLink("Núverandi borð", "Active", "Level", new { gameId = gameEntry.GameId }, new { }) |
                @Html.ActionLink("Öll borð", "GameLevelIndex", "Game", new { gameId = gameEntry.GameId }, new { })
                
            </div>
            <div class="gamepoints">
                <p>Stigafjöldi: @(gameEntry.Points.HasValue ? gameEntry.Points.ToString() : "Engin stig")</p>
                @NearestGamePoints(gameEntry)
            </div>
        </div>
    }
</div>

